Repository navigation
assistant transfer: cap pair lock and voice receipt reads while streaming - #746
Merged
joshuaswarren merged 1 commit intoNov 23, 2026
Merged
Conversation
…ming _json_member buffered a whole member before parsing it, bounded only by the member's declared size. A pair lock or voice receipt declared at hundreds of MiB, deflated to a few hundred KB, was read fully into memory before its size or hash was checked. _member_chunks now takes a byte limit and raises UnsafeArchive as soon as the decompressed stream passes it, reading at most one byte past the limit. _json_member requires a cap: 1 MiB for pair locks and voice receipts, 64 MiB for the manifest (the same limit its declared-size check already uses). Follows up joshuaswarren#740.
Owner
|
GREEN at 54c371c |
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (2 files)
Reviewed by free · Input: 130.2K · Output: 286.8K · Cached: 7.6M |
Owner
|
GREEN at 54c371c |
Owner
|
Thanks @only21mil — lock and receipt archive members now have real byte caps, so a hostile or corrupt bundle can no longer inflate unbounded memory in _member_chunks/_json_member. Merged at a3509ce. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a bundle's pair lock or voice receipt declares a large size, import reads the whole member into memory before checking its size or hash.
This follows up the review note on #740.
_json_memberjoins every chunk of a member, then parses it. The only bound is the member's declared size in the zip's central directory, and nothing checks that size before this read. Deflate compresses a run of whitespace about a thousandfold, so a 520 KB bundle can carry a 512 MiB lock.stage_importbuffers all of it while deriving the bundle's licenses, before the size and hash checks.Fix
_member_chunkstakes an optional byte limit and raisesUnsafeArchiveas soon as the decompressed stream passes it, reading at most one byte past the limit. The count comes from bytes actually read, so neither header size field can raise the limit._json_membernow requiresmax_bytes: 1 MiB for pair locks and voice receipts (real ones are a few KB), and 64 MiB for the manifest, the same limit its declared-size check already uses.Verification
A new test,
test_oversized_lock_or_receipt_stops_at_the_byte_cap, first checks that a normal bundle with a voice pack inspects and imports. Then, for both the lock and the receipt, it builds a member padded to 32 MiB and deflated to under 1 MiB, with the local header claiming 16 bytes. It expectsUnsafeArchivewith traced memory rising less than 8 MiB.2aef87273UnsafeArchiveAll the Linux steps of
collectors.ymlpass on Python 3.14 and on 3.11, run one after the other.privacy_check.pyreports clean.Repro output
Generated with Claude Opus 5.5 in T3 Code Nightly